﻿using Microsoft.AspNetCore.Mvc;
using SportsPlatform.Dto.SportBusiness.Category;
using SportsPlatform.SportBusiness.ISportBusiness;
using SportsPlatform.Base;
using SportsPlatform.Query.SportBusiness.Category;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SportsPlatform.Filters;
using SportsPlatform.Enums;

namespace SportsPlatform.Controllers
{

    [ActionAuthorization]
    [Route("api/[controller]/[action]")]
    public class CategoryController : SportsPlatformControllerBase
    {
        private ICategoryService _service;
        public CategoryController(ICategoryService service)
        {
            _service = service;
        }

        /// <summary>
        /// 查询资讯分类分页后的数据
        /// </summary>
        /// <param name="query">查询条件</param>
        /// <returns></returns>
        [HttpPost]
        [Log(OperationType.QueryList)]
        public async Task<PagePagingDto<CategoryDto>> GetCategoryDtoPage([FromBody] GetCategoryQuery query)
        {
            return await _service.GetCategoryDto(query);
        }

        /// <summary>
        /// 新增资讯分类
        /// </summary>
        /// <param name="addCategoryQuery">传入参数</param>
        /// <returns></returns>
        [HttpPost]
        [Log(OperationType.AddEntity)]
        public async Task<BaseResultDto> AddCategory([FromBody] AddCategoryQuery addCategoryQuery)
        {
            return await _service.AddStart(addCategoryQuery);
        }

        /// <summary>
        /// 更新资讯分类
        /// </summary>
        /// <param name="updateCategoryQuery">传入参数</param>
        /// <returns></returns>
        [HttpPost]
        [Log(OperationType.EditEntity)]
        public async Task<BaseResultDto> UpdateCategory([FromBody] UpdateCategoryQuery updateCategoryQuery)
        {
            return await _service.UpdateStart(updateCategoryQuery);
        }

        /// <summary>
        /// 开始删除资讯分类
        /// </summary>
        /// <param name="deleteCategoryQuery">传入参数</param>
        /// <returns></returns>
        [HttpPost]
        [Log(OperationType.DeleteEntity)]
        public async Task<BaseResultDto> UpdateDeleteCategory([FromBody] DeleteCategoryQuery deleteCategoryQuery)
        {
            return await _service.UpdateDeleteCategory(deleteCategoryQuery);
        }

        /// <summary>
        /// 更新状态
        /// </summary>
        /// <param name="updateSateQuery">传入参数</param>
        /// <returns></returns>
        [HttpPost]
        [Log(OperationType.EditEntityState)]
        public async Task<BaseResultDto> UpdateCategorySate([FromBody] UpdateCategorySateQuery updateSateQuery)
        {
            return await _service.UpdateStateStart(updateSateQuery);
        }

        /// <summary>
        /// 获取分类列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Log(OperationType.QueryList)]
        public async Task<ResultListDto<CategoryDto>> GetAllCategorys(Guid? Id, Guid? CompanyId)
        {
            return await _service.GetAll(Id, CompanyId);
        }

        /// <summary>
        /// 获取该标识下的分类
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet]
        [Log(OperationType.QueryEntity)]
        public async Task<ResultDto<GetCategoryEditDto>> GetByCategoryId(Guid Id)
        {
            return await _service.GetByCategoryId(Id);
        }
    }
}
